/*******************************************************************************
 * Copyright (c) 2011 LegSem.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl-3.0.txt
 * 
 * Contributors:
 *     LegSem - initial API and implementation
 ******************************************************************************/
package com.legsem.legstar.cci;

import com.legsem.legstar.LegStarBoundBean;

/**
 * Describes a host endpoint.
 * <p/>
 * Following the JCA specification the properties are bound.
 */
public class LegStarConnectionSpecImpl extends LegStarBoundBean implements
        LegStarConnectionSpec {

    private String hostUserID;
    private String hostPassword;
    private boolean hostTraceMode;

    public String getHostUserID() {
        return hostUserID;
    }

    public void setHostUserID(String hostUserID) {
        String oldHostUserID = getHostUserID();
        this.hostUserID = hostUserID;
        firePropertyChange("HostUserID", oldHostUserID, hostUserID);
    }

    public String getHostPassword() {
        return hostPassword;
    }

    public void setHostPassword(String hostPassword) {
        String oldHostPassword = getHostPassword();
        this.hostPassword = hostPassword;
        firePropertyChange("HostPassword", oldHostPassword, hostPassword);
    }

    public boolean isHostTraceMode() {
        return hostTraceMode;
    }

    public void setHostTraceMode(boolean hostTraceMode) {
        boolean oldHostTraceMode = isHostTraceMode();
        this.hostTraceMode = hostTraceMode;
        firePropertyChange("HostTraceMode", oldHostTraceMode, hostTraceMode);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result
                + ((hostPassword == null) ? 0 : hostPassword.hashCode());
        result = prime * result
                + ((hostUserID == null) ? 0 : hostUserID.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        LegStarConnectionSpecImpl other = (LegStarConnectionSpecImpl) obj;
        if (hostPassword == null) {
            if (other.hostPassword != null) {
                return false;
            }
        } else if (!hostPassword.equals(other.hostPassword)) {
            return false;
        }
        if (hostUserID == null) {
            if (other.hostUserID != null) {
                return false;
            }
        } else if (!hostUserID.equals(other.hostUserID)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("LegStarCciConnectionSpecImpl [hostUserID=");
        builder.append(hostUserID);
        builder.append(", hostPassword=");
        builder.append("********");
        builder.append(", hostTraceMode=");
        builder.append(hostTraceMode);
        builder.append("]");
        return builder.toString();
    }

}
